<?php

namespace app\common\util\plug;

use app\common\util\base\BaseObserver;
use app\common\util\base\BaseServer;
use think\Exception;

class PlugCreateController extends BaseObserver
{
    public function handle()
    {
        $plugInfo = $this->server->getPlugInfo();
        $plugPath = $this->server->getPlugTempPath();
        $models = ['admin', 'api', 'model','view'];
        foreach ($models as $model) {
            if (is_string($plugInfo[$model])){
                $plugInfo[$model] = [$plugInfo[$model]];
            }
            $realPlugPath = $this->server->getPlugPath().'/'.$model;
            var_dump($realPlugPath);
            foreach ($plugInfo[$model] as $adminController) {
                if (file_exists($plugPath.$model.'/'.$adminController)) {
                    if (!is_dir($realPlugPath)) {
                        mkdir($realPlugPath, 0755, true);
                    }
                    copy($plugPath.$model.'/'.$adminController, $realPlugPath. '/'. $adminController);
                }
            }
        }
        trace('控制器已就绪...');
    }
}